<?php 
class Tourismgoodscategory extends CS_Controller
{
    public function _init()
    {
        $this->load->model('tourism_goods_category_model','tourism_goods_category');
        $this->load->library('pagination');
    }
    /*
     *类别列表
     * @auther laona
     * test time 2015.5.7
     */
    public function grid($pg = 1)
    {
        $parent_id = (int)$this->input->get('parent_id')?$this->input->get('parent_id'):0;
        $config['base_url'] = base_url('tourismgoodscategory/grid');
        $config['total_rows'] = $this->tourism_goods_category->total($parent_id);
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pg_link'] = $this->pagination->create_links();
        $data['resultObj'] = $this->tourism_goods_category->page_list($parent_id);
        $data['all_rows'] = $config['total_rows'];
        $data['pg_now'] = $pg;
        $data['pg_num'] = $page_num;
        $this->load->view('tourismgoodscategory/grid',$data);
    }
    /*
     *增加类别
     * @auther laona
     **/
    public  function  add()
    {
        $data['cate'] = $this->tourism_goods_category->displayLists(0,0,1);
        $this->load->view('tourismgoodscategory/add',$data);
    }
    /*
     *增加类别处理
     * @auther laona
     **/
    public  function addPost()
    {
        $param['parent_id'] = (int)$this->input->post('parent_id');
        $param['name'] = $this->input->post('name',true);
        $param['priority'] = (int)$this->input->post('priority');

        $resultId = $this->tourism_goods_category->add_category($param);
        if ($resultId)
        {
            $this->success('tourismgoodscategory/grid', '', '保存成功！');
        }
        else
        {
            $this->error('tourismgoodscategory/add', '', '保存失败！');
        }
    }
    /*
     *类别数据更新
     * @auther laona
     **/
    public function update($id)
    {
        $result = $this->tourism_goods_category->getCategoryById($id);
        if (!$result) {
            $this->error('tourismgoodscategory/grid', '', '参数有误！');
        }
        $data['cate'] = $this->tourism_goods_category->displayLists(0, $result->parent_id,1);
        $data['result'] = $result;
        $data['states'] = 'edit';
        $data['title'] = '类别修改';
        $this->load->view('tourismgoodscategory/edit',$data);
    }
    /*
     *更新处理
     * @auther laona
     * */
    public  function updatePost()
    {
        $param['parent_id'] = (int)$this->input->post('parent_id');
        $param['name'] = $this->input->post('name',true);
        $param['priority'] = (int)$this->input->post('priority');
        $set['id'] = (int)$this->input->post('id');

        $resultId = $this->tourism_goods_category->update_category($param,$set);
        if ($resultId)
        {
            $this->success('tourismgoodscategory/grid', '', '修改成功！');
        }
        else
        {
            $this->error('tourismgoodscategory/grid', '', '修改失败！');
        }

    }
    /*
    *类别数据删除 禁用
    */
    /*public function delete($id){
        if($this->tourismGoodsCategory->delete($id)){
            $this->success('tourismgoodscategory/grid', '', '删除成功！');
        }else{
            $this->error('tourismgoodscategory/grid', '', '删除成功！');
        }

    }*/
    /*
    * ajax 产品类别 联动效果
    * @auther laona
    * test time 2015.5.7
    * */
    public function ajax_category_select($category_id){
        $cate =  $this->tourism_goods_category->page_list((int)$category_id);
        echo json_encode(array(
            'record'=>$cate->result_array(),
            'cate'=>$this->tourism_goods_category->getCategoryByLastId($category_id)
        ));exit(0);
    }
}